#ifndef XCBCAPTURE_H
#define XCBCAPTURE_H

#include <QDebug>
#include <QObject>
#include "screencapture.h"
#include <xcb/xcb.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/keysymdef.h>
extern "C"{
#include <xdo.h>
}


class XcbCapture : public ScreenCapture
{
    Q_OBJECT
public:
    explicit XcbCapture(int winId, QObject *parent = nullptr);
    ~XcbCapture() override;

    void updateFramebuffer() override;
    int getFramebufferSize() override;
    QByteArray getFramebuffer() override;
    void getFramebuffer(char* data) override;
    AVPixelFormat pixelFormat() override;
    static xcb_screen_t* get_screen(const xcb_setup_t *setup, int screen_num);
    int winId() override;

    void postMouseEvent(int button, bool isPress, int x,int y) override;
    void postKeyEvent(int key, bool isPress) override;

private:
    const char* translateKeyCode(int key);
private:
    xcb_connection_t *conn;
    xcb_screen_t *screen;
    xcb_window_t window;
    xcb_get_image_reply_t *img;
    Display *display;
    xdo_t *xdo;
};

#endif // XCBCAPTURE_H
